﻿using JetBrains.Annotations;
using NineSeas.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Environment.Extensions;
using Orchard.Localization;

namespace NineSeas.Handlers
{
    [UsedImplicitly]
    public class NineSeasSettingsHandler : ContentHandler
    {
        public Localizer T { get; set; }

        public NineSeasSettingsHandler(IRepository<NineSeasSettingsPartRecord> repository)
        {
            T = NullLocalizer.Instance;
            Filters.Add(new ActivatingFilter<NineSeasSettingsPart>("Site"));

            Filters.Add(StorageFilter.For(repository));
        }
        protected override void GetItemMetadata(GetContentItemMetadataContext context)
        {
            if (context.ContentItem.ContentType != "Site")
                return;

            base.GetItemMetadata(context);

            var groupInfo = new GroupInfo(T("NineSeas")); // Addig a new group to the "Settings" menu.
            groupInfo.Id = "NineSeasSettings";
            context.Metadata.EditorGroupInfo.Add(groupInfo);
        }
    }
}